package utility

import (
	"fmt"
	"github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi"
	"root/config"

)


func Send(phone string , code int) bool {

	config, err1 := config.GetConfig("cms")
	if(err1 != nil){
		return  false
	}
	client, err := dysmsapi.NewClientWithAccessKey("cn-qingdao", config["Ak"].(string), config["As"].(string))
	request := dysmsapi.CreateSendSmsRequest()
	request.Scheme = "https"
	request.PhoneNumbers = phone
	request.SignName = config["Sign"].(string)
	request.TemplateCode = config["TemplateCode"].(string)
	request.TemplateParam = fmt.Sprintf("{'code':%d}",code)

	response, err := client.SendSms(request)
	if err != nil {
		fmt.Print(err.Error())
		return false
	}
	if(response.Code == "OK" && response.Message == "ok"){
		return true
	}
	fmt.Printf("response is %#v\n", response)
	return false

}